package com.kgis.map.geometry.basetype {
   import flash.system.Capabilities;

   /**
    * 地图单位
    */
   public class Unit {
      public static var DEGREE:String = "degrees";
      public static var METER:String = "m";
      public static var KILOMETER:String = "km";
      public static var FOOT:String = "ft";
      public static var MILE:String = "mile";
      public static var INCH:String = "inch";

      public static var DEGREE_CN:String = "度";
      public static var METER_CN:String = "米";
      public static var KILOMETER_CN:String = "公里";
      public static var FOOT_CN:String = "英尺";
      public static var MILE_CN:String = "英里";
      public static var INCH_CN:String = "英寸";

      public static var DOTS_PER_INCH:int = 72;

      public static function getInchesPerUnit(unit:String):Number {
         switch (unit) {
            case Unit.INCH:
               return 1.0;
               break;
            case Unit.FOOT:
               return 12.0;
               break;
            case Unit.MILE:
               return 63360.0;
               break;
            case Unit.METER:
               return 39.3701;
               break;
            case Unit.KILOMETER:
               return 39370.1;
               break;
            case Unit.DEGREE:
               return 4374754;
               break;
            case Unit.INCH_CN:
               return 1.0;
               break;
            case Unit.FOOT_CN:
               return 12.0;
               break;
            case Unit.MILE_CN:
               return 63360.0;
               break;
            case Unit.METER_CN:
               return 39.3701;
               break;
            case Unit.KILOMETER_CN:
               return 39370.1;
               break;
            case Unit.DEGREE_CN:
               return 4374754;
               break;
            default:
               return 0;
         }
      }

      public static function getResolutionFromScale(scale:Number, units:String = null):Number {

         if (units == null) {
            units = Unit.DEGREE;
         }
         var dpiScreen:Number = flash.system.Capabilities.screenDPI;

         var normScale:Number = (scale > 1.0) ? (1.0 / scale) : scale;

         var resolution:Number = 1 / (normScale * Unit.getInchesPerUnit(units) * dpiScreen);
         return resolution;
      }

      public static function getScaleFromResolution(resolution:Number, units:String):Number {
         if (units == null) {
            units = Unit.DEGREE;
         }
         var dpiScreen:Number = flash.system.Capabilities.screenDPI;
         var scale:Number = resolution * Unit.getInchesPerUnit(units) * dpiScreen;
         return scale;
      }

   }
}

